import Vue from 'vue'
import VueRouter from 'vue-router'
import layout from '@/layout'
Vue.use(VueRouter)

// 固定路由
export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/Login'), // 登录页
    meta: { title: '登录' }
  },
  {
    path: '/preview',
    name: 'Preview',
    component: () => import('@/views/preview/Preview'), // 预览全文
    meta: { title: '预览全文' }
  },
  {
    path: '/system',
    component: layout,
    children: [{
      path: 'systemHelp',
      name: 'SystemHelp',
      component: () => import('@/views/help/SystemHelp'), // 系统帮助
      meta: { title: '系统帮助' }
    }]
  },
  {
    path: '/test',
    name: 'Test',
    component: () => import('@/views/test/test'), // 测试用例页面
    meta: { title: '测试页面' }
  }
]
// 动态路由(需要动态获取的)
export const asyncRoutes = [
  {
    path: '/',
    component: layout, // 首页
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'HomePage',
      component: () => import('@/views/home/HomePage'), // 首页
      meta: { title: '首页', icon: 'icon-shouye', iconColor: '#409EFF', hidden: true }
    }]
  },
  {
    path: '/system',
    name: 'System',
    component: layout, // 系统设置
    redirect: '/system/dictionary',
    meta: { title: '系统设置', icon: 'icon-shezhi', iconColor: '#75b0ff' },
    children: [{
      path: 'dictionary',
      name: 'Dictionary',
      component: () => import('@/views/system/dictionary/Dictionary'), // 数据字典
      meta: { title: '数据字典', icon: 'icon-shujuzidian', iconColor: '#29c19a' }
    },
    {
      path: 'systemParameter',
      name: 'SystemParameter',
      component: () => import('@/views/system/parameter/SystemParameter'), // 系统参数
      meta: { title: '系统参数', icon: 'icon-xitongcanshu', iconColor: '#f4b645' }
    },
    {
      path: 'pathManage',
      name: 'PathManage',
      component: () => import('@/views/system/path/PathManage'), // 全文路径管理
      meta: { title: '全文路径管理', icon: 'icon-icon-lujingguanli', iconColor: '#fb8e8d' }
    },
    {
      path: 'saveFile',
      name: 'SaveFile',
      component: () => import('@/views/system/file/SaveFile'), // 归档范围和保管期限
      meta: { title: '归档范围和保管期限', icon: 'icon-baoguanxiangicon', iconColor: '#f4b645' }
    },
    {
      path: 'databaseDefinition',
      name: 'DatabaseDefinition',
      component: () => import('@/views/system/datatable/DatabaseDefinition'), // 数据表定义
      meta: { title: '数据表定义', icon: 'icon-shujubiao', iconColor: '#409EFF' }
    },
    {
      path: 'folderManage',
      name: 'FolderManage',
      component: () => import('@/views/system/fonds/FolderManage'), // 全宗管理
      meta: { title: '全宗管理', icon: 'icon-quanzong', iconColor: '#42c5ff' }
    },
    {
      path: 'categoryManage',
      name: 'CategoryManage',
      component: () => import('@/views/system/class/CategoryManage'), // 门类管理
      meta: { title: '门类管理', icon: 'icon-menleitongji', iconColor: '#e64dff' }
    },
    {
      path: 'cataLog',
      name: 'CataLog',
      component: () => import('@/views/system/catalog/CataLog'), // 分类管理
      meta: { title: '分类管理', icon: 'icon-fenlei', iconColor: '#ff4c42' }
    },
    {
      path: 'formModel',
      name: 'FormModel',
      component: () => import('@/views/system/model/FormModel'), // 窗体模型
      meta: { title: '窗体模型', icon: 'icon-chuangti', iconColor: '#49af28' }
    }]
  },
  {
    path: '/auth',
    name: 'Auth',
    component: layout, // 权限管理
    redirect: '/auth/userManage',
    meta: { title: '权限管理', icon: 'icon-anquan', iconColor: '#fb8e8d' },
    children: [{
      path: 'userManage',
      name: 'UserManage',
      component: () => import('@/views/auth/user/UserManage'), // 用户管理
      meta: { title: '用户管理', icon: 'icon-yonghuguanli', iconColor: '#29c19a' }
    }, {
      path: 'roleManage',
      name: 'RoleManage',
      component: () => import('@/views/auth/role/RoleManage'), // 角色管理
      meta: { title: '角色管理', icon: 'icon-jiaoseguanli', iconColor: '#f4b645' }
    }, {
      path: 'job',
      name: 'Job',
      component: () => import('@/views/auth/job/JobManage'), // 职务管理
      meta: { title: '职务管理', icon: 'icon-zhiwu', iconColor: '#fb8e8d' }
    },
    {
      path: 'person',
      name: 'Person',
      component: () => import('@/views/auth/person/PersonManage'), // 人员管理
      meta: { title: '人员管理', icon: 'icon-renyuan', iconColor: '#f4b645' }
    }, {
      path: 'editPassword',
      name: 'EditPassword',
      component: () => import('@/views/login/EditPassword'), // 修改密码
      meta: { title: '修改密码', icon: 'icon-buchongiconsvg06', iconColor: '#409EFF' }
    }, {
      path: 'baseMenu',
      name: 'BaseMenu',
      component: () => import('@/views/auth/menu/BaseMenu'), // 菜单设置
      meta: { title: '菜单设置', icon: 'icon-caidan', iconColor: '#42c5ff' }
    }, {
      path: 'baseLog',
      name: 'BaseLog',
      component: () => import('@/views/auth/logs/BaseLog'), // 操作日志
      meta: { title: '操作日志', icon: 'icon-rizhi', iconColor: '#e64dff' }
    }, {
      path: 'speedy',
      name: 'Speedy',
      component: () => import('@/views/auth/speedy/SpeedyManage'), // 桌面快捷方式
      meta: { title: '桌面快捷方式', icon: 'icon-kuaijie', iconColor: '#ff4c42' }
    }, {
      path: 'interfaceMap',
      name: 'InterfaceMap',
      component: () => import('@/views/auth/interface/InterfaceMap'), // 接口映射
      meta: { title: '接口映射', icon: 'icon-yingshe', iconColor: '#49af28' }
    }]
  },
  {
    path: '/file',
    name: 'File',
    component: layout,
    redirect: '/file/preFile',
    meta: { title: '档案接收', icon: 'icon-danganjieshou', iconColor: '#6ce17c' },
    children: [{
      path: 'preFile',
      name: 'PreFile',
      component: () => import('@/views/electron-center/PreFile'), // 电子文件接收预处理
      meta: { title: '电子文件接收预处理', icon: 'icon-401', iconColor: '#f4b645' }
    }, {
      path: 'fileCenter',
      name: 'FileCenter',
      component: () => import('@/views/electron-center/FileCenter'), // 电子文件中心
      meta: { title: '电子文件中心', icon: 'icon-dianziwenjianguanli1', iconColor: '#fb8e8d' }
    }]
  },
  {
    path: '/dynamic/1',
    name: '1',
    component: layout,
    meta: { title: '预归档平台', icon: 'icon-shouji', iconColor: '#54a7f6' },
    children: [{
      path: '12',
      name: '12',
      component: () => import('@/views/dynamic'),
      meta: { title: '上海市民政局', icon: 'icon-shouji', iconColor: '#54a7f6' },
      children: [{
        path: '11',
        name: '11',
        component: () => import('@/views/dynamic'),
        meta: { title: '诉讼档案', icon: 'icon-susong', iconColor: '#3bd8ae', mode: 1 }
      }, {
        path: '22',
        name: '22',
        component: () => import('@/views/dynamic'),
        meta: { title: '科研档案以卷整理', icon: 'icon-dangan7', iconColor: '#fb6462', mode: 2 }
      }, {
        path: '33',
        name: '33',
        component: () => import('@/views/dynamic'),
        meta: { title: '会计档案以卷整理', icon: 'icon-dangan5', iconColor: '#fd9694', mode: 3 }
      }, {
        path: '44',
        name: '44',
        component: () => import('@/views/dynamic'),
        meta: { title: '文书档案以件整理', icon: 'icon-dangan6', iconColor: '#3bd8ae', mode: 4 }
      }, {
        path: '55',
        name: '55',
        component: () => import('@/views/dynamic'),
        meta: { title: '声像档案以件整理', icon: 'icon-dangan1', iconColor: '#ffd127', mode: 5 }
      }]
    }]
  },
  {
    path: '/dynamic/2',
    name: '2',
    component: layout,
    meta: { title: '档案接收', icon: 'icon-shenpi', iconColor: '#f4b645' },
    children: [{
      path: '111',
      name: '111',
      component: () => import('@/views/dynamic'),
      meta: { title: '诉讼档案', icon: 'icon-susong', iconColor: '#3bd8ae', mode: 1 }
    }, {
      path: '222',
      name: '222',
      component: () => import('@/views/dynamic'),
      meta: { title: '科研档案以卷整理', icon: 'icon-dangan7', iconColor: '#fb6462', mode: 2 }
    }, {
      path: '333',
      name: '333',
      component: () => import('@/views/dynamic'),
      meta: { title: '会计档案以卷整理', icon: 'icon-dangan5', iconColor: '#fd9694', mode: 3 }
    }, {
      path: '444',
      name: '444',
      component: () => import('@/views/dynamic'),
      meta: { title: '文书档案以件整理', icon: 'icon-dangan6', iconColor: '#3bd8ae', mode: 4 }
    }, {
      path: '555',
      name: '555',
      component: () => import('@/views/dynamic'),
      meta: { title: '声像档案以件整理', icon: 'icon-dangan1', iconColor: '#ffd127', mode: 5 }
    }]
  },
  {
    path: '/dynamic/3',
    name: '3',
    component: layout,
    meta: { title: '档案整理', icon: 'icon-zhuanxiangyanshou', iconColor: '#fb8e8d' },
    children: [{
      path: '1111',
      name: '1111',
      component: () => import('@/views/dynamic'),
      meta: { title: '诉讼档案', icon: 'icon-susong', iconColor: '#3bd8ae', mode: 1 }
    }, {
      path: '2222',
      name: '2222',
      component: () => import('@/views/dynamic'),
      meta: { title: '科研档案以卷整理', icon: 'icon-dangan7', iconColor: '#fb6462', mode: 2 }
    }, {
      path: '3333',
      name: '3333',
      component: () => import('@/views/dynamic'),
      meta: { title: '会计档案以卷整理', icon: 'icon-dangan5', iconColor: '#fd9694', mode: 3 }
    }, {
      path: '4444',
      name: '4444',
      component: () => import('@/views/dynamic'),
      meta: { title: '文书档案以件整理', icon: 'icon-dangan6', iconColor: '#3bd8ae', mode: 4 }
    }, {
      path: '5555',
      name: '5555',
      component: () => import('@/views/dynamic'),
      meta: { title: '声像档案以件整理', icon: 'icon-dangan1', iconColor: '#ffd127', mode: 5 }
    }]
  },
  {
    path: '/appraisal',
    component: layout, // 档案鉴定
    children: [{
      path: 'appraisal',
      name: 'Appraisal',
      component: () => import('@/views/appraisal/Appraisal'), // 档案鉴定
      meta: { title: '档案鉴定', icon: 'icon-jiandingjigou', iconColor: '#3bd8ae', hidden: true }
    }]
  },
  {
    path: '/archiveCompilation',
    component: layout, // 档案编研
    children: [{
      path: 'archiveCompilation',
      name: 'ArchiveCompilation',
      component: () => import('@/views/compilation/ArchiveCompilation'), // 档案编研
      meta: { title: '档案编研', icon: 'icon-shishibianyan', iconColor: '#fb8e8d', hidden: true }
    }]
  },
  {
    path: '/archiveSpecial',
    component: layout, // 档案专题
    children: [{
      path: 'archiveSpecial',
      name: 'ArchiveSpecial',
      component: () => import('@/views/special/ArchiveSpecial'), // 档案专题
      meta: { title: '档案专题', icon: 'icon-zhuanti', iconColor: '#e64dff', hidden: true }
    }]
  },
  {
    path: '/custody',
    name: 'Custody',
    component: layout, // 档案保存
    redirect: '/custody/oracle',
    meta: { title: '档案保存', icon: 'icon-baocun_mian', iconColor: '#54a7f6' },
    children: [{
      path: 'oracle',
      name: 'Oracle',
      component: () => import('@/views/custody/oracle'), // 数据库管理
      meta: { title: '数据库管理', icon: 'icon-shujukuguanli', iconColor: '#3bd8ae' }
    },
    {
      path: 'fulltext',
      name: 'Fulltext',
      component: () => import('@/views/custody/fulltext'), // 全文管理
      meta: { title: '全文管理', icon: 'icon-wj-xgwj-t', iconColor: '#79a3fc' }
    },
    {
      path: 'storage',
      name: 'Storage',
      component: () => import('@/views/custody/storage'), // 存储监控
      meta: { title: '存储监控', icon: 'icon-monitor', iconColor: '#fb6462' }
    },
    {
      path: 'check',
      name: 'Check',
      component: () => import('@/views/custody/check'), // 四性检测
      meta: { title: '四性检测', icon: 'icon-chaxun1', iconColor: '#fd9694' }
    },
    {
      path: 'access',
      name: 'Access',
      component: () => import('@/views/custody/access'), // 非法访问
      meta: { title: '非法访问', icon: 'icon-fangwen1', iconColor: '#3bd8ae' }
    },
    {
      path: 'tactics',
      name: 'Tactics',
      component: () => import('@/views/custody/tactics'), // 安全策略
      meta: { title: '安全策略', icon: 'icon-anquan', iconColor: '#ffd127' }
    }]
  },
  {
    path: '/archivalEvolution',
    component: layout, // 档案沿革
    children: [{
      path: 'archivalEvolution',
      name: 'ArchivalEvolution',
      component: () => import('@/views/evolution/ArchivalEvolution'), // 档案沿革
      meta: { title: '档案沿革', icon: 'icon-danweiyange', iconColor: '#fd9694', hidden: true }
    }]
  },
  {
    path: '/search',
    name: 'Search',
    component: layout, // 档案利用
    redirect: '/search/querySearch',
    meta: { title: '档案利用', icon: 'icon-sousuo1', iconColor: '#3bd8ae' },
    children: [{
      path: 'querySearch',
      name: 'QuerySearch',
      component: () => import('@/views/search/query/QuerySearch'), // 档案目录查询
      meta: { title: '档案目录查询', icon: 'icon-chaxun1', iconColor: '#29c19a' }
    }, {
      path: 'fullSearch',
      name: 'FullSearch',
      component: () => import('@/views/search/full/FullSearch'), // 全文检索查询
      meta: { title: '全文检索查询', icon: 'icon-sousuo1', iconColor: '#f4b645' }
    }, {
      path: 'borrowManage',
      name: 'BorrowManage',
      component: () => import('@/views/search/borrow/BorrowManage'), // 档案借阅管理
      meta: { title: '档案借阅管理', icon: 'icon-jieyue', iconColor: '#fb8e8d' }
    }, {
      path: 'urlBorrow',
      name: 'UrlBorrow',
      component: () => import('@/views/search/borrow/UrlBorrow'), // url借阅管理
      meta: { title: 'url借阅管理', icon: 'icon-jieyue1', iconColor: '#f4b645' }
    }]
  },
  {
    path: '/desktop',
    name: 'Desktop',
    component: layout, // 桌面管理
    redirect: '/desktop/resourceManage',
    meta: { title: '桌面管理', icon: 'icon-zhuomian', iconColor: '#fb8e8d' },
    children: [{
      path: 'resourceManage',
      name: 'ResourceManage',
      component: () => import('@/views/desktop/ResourceManage'), // 资源管理
      meta: { title: '资源管理', icon: 'icon-resource-management', iconColor: '#29c19a' }
    }, {
      path: 'desktopPersonal',
      name: 'DesktopPersonal',
      component: () => import('@/views/desktop/DesktopPersonal'), // 个性设置
      meta: { title: '个性设置', icon: 'icon-icon-test', iconColor: '#f4b645' }
    }]
  },
  {
    path: '/workFlow',
    component: layout, // 工作流
    children: [{
      path: 'workFlow',
      name: 'WorkFlow',
      component: () => import('@/views/work-flow/Workflow'), // 工作流
      meta: { title: '工作流', icon: 'icon-gongzuoliu', iconColor: '#ffd127', hidden: true }
    }]
  },
  {
    path: '/statisticalAnalysis',
    component: layout, // 统计分析
    children: [{
      path: 'statisticalAnalysis',
      name: 'StatisticalAnalysis',
      component: () => import('@/views/statistics/Statistics'), // 统计分析
      meta: { title: '统计分析', icon: 'icon-tongji', iconColor: '#79a3fc', hidden: true }
    }]
  },
  {
    path: '/recoverStand',
    component: layout, // 回收站
    children: [{
      path: 'recoverStand',
      name: 'RecoverStand',
      component: () => import('@/views/recover/RecoverStand'), // 回收站
      meta: { title: '回收站', icon: 'icon-huishouzhan', iconColor: '#f9695c', hidden: true }
    }]
  },
  {
    path: '/newsCenter',
    component: layout, // 新闻中心
    children: [{
      path: 'newsCenter',
      name: 'NewsCenter',
      component: () => import('@/views/news/NewsCenter'), // 新闻中心
      meta: { title: '新闻中心', icon: 'icon-xinwen1', iconColor: '#79a3fc', hidden: true }
    }]
  }
]

// 解决重复点击导航路由报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const createRouter = () => new VueRouter({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes.concat(asyncRoutes)
})

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
